package com.megvii.corelib.util;

import android.app.AlertDialog;
import android.content.Context;

import com.megvii.corelib.components.IconTextView;

import java.util.List;

/**
 * Created by linyue on 16/2/3.
 */
public class IconTextListDialog implements IconTextView.IconTextListener
{
    private IconTextListListener listener;

    private AlertDialog dialog;

    /**
     * @param context
     * @param listener
     * @param titleText null就显示默认的
     */
    public void showDeviceSelector(Context context, final IconTextListListener listener,
            String titleText, List<Integer> iconRess, List<String> texts)
    {
        this.listener = listener;
        final IconTextView view = new IconTextView(context);
        view.setTitleText(titleText);
        view.setData(iconRess, texts);
        view.setListener(this);
        AlertDialog.Builder builder = new AlertDialog.Builder(context,
                AlertDialog.THEME_HOLO_LIGHT);
        builder.setView(view);
        dialog = builder.show();
        dialog.setCanceledOnTouchOutside(true);
    }

    @Override
    public void onChoose(int position)
    {
        dialog.hide();
        if (listener != null)
        {
            listener.onSelect(position);
        }
    }

    @Override
    public void onCancel()
    {
        dialog.hide();
    }

    public interface IconTextListListener
    {
        public void onSelect(int position);
    }
}
